|
|
|
|
|
|
|
call it from Visual Basic.1 Fortunately, almost all DLL functions are exported with this calling convention. |
|
|
|
|
|
|
|
|
In the stdcall calling convention, the following rules apply: |
|
|
|
|
|
|
|
|
Parameters are passed onto the stack from right to left. |
|
|
|
|
|
|
|
|
The called function pops parameters from the stack. |
|
|
|
|
|
|
|
|
Why are parameters pushed onto the stack from right to left? Consider the following function: |
|
|
|
|
|
|
|
|
Function MyFunction(Byval A as Long, ByVal B As Long) As Long |
|
|
|
|
|
|
|
|
Now look at Figure T4-5, which shows the stack frame for the function when it is called with the line: |
|
|
|
|
|
|
|
|
The leftmost parameter is pushed onto the stack last, which places it closest to the BP in the stack frame for the function. Why should this matter? The truth is that it doesn't. With some calling conventions, passing parameters from right to left makes it easier to handle situations where you have a variable number of parameters, but that doesn't apply in this case. The stdcall calling convention uses another approach, which involves passing a pointer to an array. As a Visual Basic programmer, you won't need to worry about the order. |
|
|
|
|
|
|
|
|
Figure T4-5:
Stack frame for a function with two parameters |
|
|
|
|
|
|
|
|
If the calling function pushes parameters onto the stack and the called function pops them from the stack, the two functions must agree on both the |
|
|
|
 |
|
 |
|
|
1 Or can you? As you work your way through the puzzles, you may find a surprise or two on this score. |
|
|
|
|
|